package com.feicheng.persistence.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feicheng.persistence.entity.Lastcount;
import com.feicheng.persistence.mapper.LastcountMapper;
import com.feicheng.persistence.service.ILastcountService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cailongyang
 * @since 2023-08-05
 */
@Service
public class LastcountServiceImpl extends ServiceImpl<LastcountMapper, Lastcount> implements ILastcountService {

    @Override
    public synchronized Integer getValueByColumn(String column) {

        Lastcount lastcount = this.getById(1);
        JSONObject lastcountjson = JSONObject.parseObject(JSONObject.toJSONString(lastcount));

        int count = lastcountjson.getIntValue(column);

        count++;

        lastcountjson.put(column, count);

        lastcount = JSONObject.parseObject(lastcountjson.toJSONString(), Lastcount.class);

        this.updateById(lastcount);

        return count;
    }
}
